package org.henry.springboot1.config;

import java.beans.PropertyVetoException;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.env.Environment;

import com.mchange.v2.c3p0.ComboPooledDataSource;

@Configuration
	public class DataSourceConfig {
		@Autowired
	    private Environment env;
		
	    @Bean(name="dataSource")
	    public ComboPooledDataSource dataSource() throws PropertyVetoException {
	        ComboPooledDataSource dataSource = new ComboPooledDataSource();
	        dataSource.setDriverClass(env.getProperty("jdbc.driverClassName"));
	        dataSource.setJdbcUrl(env.getProperty("jdbc.url"));
	        dataSource.setUser(env.getProperty("jdbc.username"));
	        dataSource.setPassword(env.getProperty("jdbc.password"));
	        dataSource.setMaxPoolSize(20);
	        dataSource.setMinPoolSize(5);
	        dataSource.setInitialPoolSize(10);
	        dataSource.setMaxIdleTime(300);
	        dataSource.setAcquireIncrement(5);
	        dataSource.setIdleConnectionTestPeriod(60);
	        
	        return dataSource;
	    }
	    
	    
	}
